package com.liao.ticket.controller;

import com.liao.ticket.common.exception.ErrorCode;
import com.liao.ticket.dao.pojo.Seat;
import com.liao.ticket.service.SeatService;
import com.liao.ticket.vo.Result;
import com.liao.ticket.vo.params.SeatParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 接口测试成功
 * 1.0.0
 * 10.16 13:26
 */
@RestController
@RequestMapping("seat")
public class SeatUpdateController {
    @Autowired
    private SeatService seatService;

    // 通过 舱位id 查询 舱位
    @GetMapping("one/{id}")
    public Result queryOneById(@PathVariable Long id) {
        Seat seat = seatService.selectOneById(id);
        if (seat == null) {
            return Result.fail(ErrorCode.FLIGHT_SEAT_NO_EXIT);
        }
        return Result.success(seat);
    }

    // 通过 航班id 查询 舱位
    @GetMapping("list/{id}")
    public Result queryListByFid(@PathVariable Long id) {
        List<Seat> seatList = seatService.selectListByFid(id);
        return Result.success(seatList);
    }

    // 通过 航班id 添加 舱位
    @PostMapping("add")
    public Result addOne(@RequestBody SeatParams seatParams) {
        return seatService.save(seatParams);
    }

    // 通过 航班id 和 舱位id 修改 舱位
    @PostMapping("update")
    public Result updateOne(@RequestBody SeatParams seatParams) {
        return seatService.updateOneByIdAndFid(seatParams);
    }

    // 通过 航班id 和 舱位id 删除 舱位
    @GetMapping("delete")
    public Result deleteOne(@RequestBody SeatParams seatParams) {
        return seatService.deleteOneByIdAndFid(seatParams);
    }

}
